﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Windows;

namespace WikcLib.Log
{
    public class Elog
    {

        public static void Log(string strMsg, string strFilePath, string strFileName)
        {
            Log(strMsg, strFilePath, strFileName, false);
        }
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <param name="strMsg">日志信息</param>
        /// <param name="strFilePath">日志路径</param>
        /// <param name="strFileName">日志文件名称</param> 
        /// <param name="IsEverydayLog">一天一个日志</param>
        public static void Log(string strMsg, string strFilePath, string strFileName,Boolean IsEverydayLog)
        {
            try
            { 
                string logfile = strFilePath + "\\";
                if (IsEverydayLog)
                {
                    logfile = logfile + "\\" + System.DateTime.Now.ToString("yyyyMMdd-");
                }
                logfile = logfile + strFileName + ".log";
                StreamWriter sw = new StreamWriter(logfile, true);
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + strMsg);
                sw.Close();
            }
            catch (Exception)
            {
                throw;
            }
        }

        private static string GetAddr()
        {
            //默认路径
            string result = "D:";
            //若文件夹不存在就创建
            if (!System.IO.Directory.Exists(result))
            {
                System.IO.Directory.CreateDirectory(result);
            }
            return result;
        }
    }
}
